//
//  SoundCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 lushan. All rights reserved.
//

#import "SoundCell.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
@implementation SoundCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
//    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, WIDTH / 5, WIDTH / 5)];
    self.image = [[UIImageView alloc]init];
    self.image.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.image];
    [self.image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(10 * WID);
        make.size.mas_equalTo(WIDTH / 5);
    }];
    
//    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x + WIDTH / 5 + 20, self.image.frame.origin.y + 10, WIDTH / 4, WIDTH / 5 / 5)];
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.image.mas_right).offset(20 * WID);
        make.top.equalTo(self.image.mas_top).offset(10 * HEI);
        make.width.mas_equalTo(WIDTH / 3);
        make.height.equalTo(self.image.mas_height).multipliedBy(0.2);
    }];
    
//    self.enname = [[UILabel alloc]initWithFrame:CGRectMake(self.image.frame.origin.x + WIDTH / 5 + 20, WIDTH / 9, WIDTH / 4, WIDTH / 5 / 5)];
    self.enname = [[UILabel alloc]init];
    self.enname.font = [UIFont systemFontOfSize:10];
    self.enname.textColor = [UIColor colorWithRed:132 / 255.0 green:148 / 255.0 blue:220 / 255.0 alpha:1.0];
    [self.contentView addSubview:self.enname];
    [self.enname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(10 * HEI);
        make.size.equalTo(self.nameLabel);
    }];
    
    self.contentLabel = [[UILabel alloc]init];
    self.contentLabel.font = [UIFont systemFontOfSize:10];
    self.contentLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.equalTo(self.enname.mas_bottom).offset(10 * HEI);
        make.right.mas_equalTo(10 * WID);
        make.height.equalTo(self.nameLabel.mas_height);
    }];
    
}

// model的set方法
- (void)setSoundModel:(SoundModel *)soundModel{
    _soundModel = soundModel;
    self.contentLabel.text = self.soundModel.desc;
    self.nameLabel.text = self.soundModel.title;
    self.enname.text = [NSString stringWithFormat:@"by:%@", [self.soundModel.userinfo objectForKey:@"uname"]];
    NSURL *url = [NSURL URLWithString:self.soundModel.coverimg];
    
    [self.image sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"holderImage.jpg"]];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
